<template>
  <div class='container'>
    <el-dialog
      title="题目预览"
      :visible="dialogVisible"
      width="70%"
      @close="close">
      <el-row>
        <el-col :span="6">【题型】:{{myDate.questionType | qt}}</el-col>
        <el-col :span="6">【编号】:{{myDate.id}}</el-col>
        <el-col :span="6">【难度】:{{myDate.difficulty | dt}}</el-col>
        <el-col :span="6">【标签】:{{myDate.remarks}}</el-col>
        <el-col :span="6">【学科】:{{myDate.subjectName}}</el-col>
        <el-col :span="6">【目录】:{{myDate.directoryName}}</el-col>
        <el-col :span="6">【方向】:{{myDate.direction}}</el-col>
      </el-row>
      <hr>
      【题干】:<div v-html="myDate.question" style="color:#0000ff"></div>
      <div v-if="myDate.questionType!==3">
        <div>{{myDate.questionType | qt}}题 选项: (以下选中的选项为正确答案)</div>
        <div v-for="item in myDate.options" :key="item.id" style="padding:8px 0">
          <el-radio v-if="myDate.questionType==='1'" :value="item.isRight" :label="1">{{item.title}}</el-radio>
          <el-checkbox  v-if="myDate.questionType==='2'" :value="item.isRight?true:false">{{item.title}}</el-checkbox>
        </div>
      </div>
      <hr>
      【参考答案】:<el-button type="danger" size="small" @click="videoPreview">视频答案预览</el-button>
      <div v-show="play" class="video">
        <video :src="myDate.videoURL" ref="video" controls></video>
      </div>
      <hr>
      【答案解析】:<div v-html="myDate.answer" style="display:inline-block"></div>
      <hr>
      【题目备注】:{{myDate.remarks}}

      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="close">关 闭</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { detail } from '@/api/hmmm/questions.js'
import { difficulty, questionType } from '@/api/hmmm/constants.js'
export default {
  props: {
    dialogVisible: {
      type: Boolean,
      default: false
    },
    data: {
      type: Object,
      default: () => {}
    }
  },
  data () {
    return {
      isNext: true, // 详情参数
      myDate: {}, // 详情数据列表
      play: false // 视频播放

    }
  },
  filters: {
    qt (value) {
      const res = questionType.find(item => item.value === +value)
      return res ? res.label : '未知'
    },
    dt (value) {
      const res = difficulty.find(item => item.value === +value)
      return res ? res.label : '未知'
    }

  },
  methods: {
    // 关闭对话框
    close () {
      this.$emit('update:dialogVisible', false)
      this.play = false
      this.$refs.video.pause()
    },

    // 显示对话框详情
    async open () {
      const { data } = await detail({ id: this.data.id, isNext: this.isNext })
      // console.log(data)
      this.myDate = data
    },

    // 视频答案预览
    videoPreview () {
      this.play = true
      this.$refs.video.play()
    }
  }
}
</script>

<style scoped lang='scss'>
.el-col{
  padding: 10px 0;
}

.video{
  margin-top: 10px;
  width: 400px;
  height: 300px;
  video{
    width: 100%;
    height: 100%;
  }
}
</style>
